package com.tfjybj.itoo.exam.provider.controller;

import org.apache.dubbo.config.annotation.Reference;;
import com.dmsdbj.itoo.tool.business.ItooResult;
import com.tfjybj.itoo.exam.entity.StaffInstitutionEntity;
import com.tfjybj.itoo.exam.provider.service.StaffInstitutionService;
import com.tfjybj.itoo.teach.FacadeApi.StaffInstitutionApi;
import com.tfjybj.itoo.teach.model.StaffInstitutionModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * StaffInstitutionController
 * staffInstitution表
 *
 * @author 杨江涛
 * @version 2.0.0
 * @since 2.0.0 2018-11-15 10:35:56
 */
@Api(tags = {"staffInstitution表接口"})
@RequestMapping(value = "/staffInstitution")
@RestController
public class StaffInstitutionController {

    @Resource
    private StaffInstitutionService staffInstitutionService;

    @Reference(check = false)
    private StaffInstitutionApi staffInstitutionApi;

    //region 模板生成：基本增删改

    /**
     * 添加
     *
     * @param model StaffInstitutionModel
     * @return 添加的结果
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "添加")
    @PostMapping(value = {"/create"})
    public ItooResult create(@RequestBody StaffInstitutionModel model) {
        if (StringUtils.isEmpty(model.getStaffId())) {
            return ItooResult.build(ItooResult.FAIL, "staffId为空");
        }
        if (StringUtils.isEmpty(model.getInstitutionId())) {
            return ItooResult.build(ItooResult.FAIL, "institutionId为空");
        }
        return staffInstitutionApi.create(model);
    }

    /**
     * 删除
     *
     * @param id 主键id
     * @return ItooResult 是否删除成功
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据id删除（单个）")
    @DeleteMapping(value = {"/delete/{id}"})
    public ItooResult delete(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        if (StringUtils.isEmpty(id)) {
            return ItooResult.build(ItooResult.FAIL, "id为空");
        }
        return staffInstitutionApi.delete(id);
    }

    /**
     * 批量删除
     *
     * @param ids ids
     * @return ItooResult 批量删除是否成功结果
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据id批量删除")
    @DeleteMapping(value = {"/deleteByIds"})
    @ApiImplicitParam(name = "ids", value = "ids", dataType = "List<String>", required = true)
    public ItooResult deleteByIds(@RequestBody List<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return ItooResult.build(ItooResult.FAIL, "ids为空");
        }
        return staffInstitutionApi.deleteByIds(ids);
    }

    /**
     * 修改
     *
     * @param model StaffInstitutionModel
     * @return 修改后的结果
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据id修改staffInstitution")
    @PutMapping(value = {"/modify"})
    public ItooResult modify(@RequestBody StaffInstitutionModel model) {
        if (StringUtils.isEmpty(model.getStaffId())) {
            return ItooResult.build(ItooResult.FAIL, "staffId为空");
        }
        if (StringUtils.isEmpty(model.getInstitutionId())) {
            return ItooResult.build(ItooResult.FAIL, "institutionId为空");
        }
        return staffInstitutionApi.modify(model);
    }

    /**
     * 根据id查找StaffInstitution
     *
     * @param id 主键id
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = {"/findById/{id}"})
    public ItooResult findById(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        if (StringUtils.isEmpty(id)) {
            return ItooResult.build(ItooResult.FAIL, "ids为空");
        }
        return staffInstitutionApi.findById(id);
    }

    /**
     * 分页查询所有StaffInstitution
     *
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "分页查询所有StaffInstitution")
    @GetMapping(value = {"/queryPageAll/{pageNo}/{pageSize}"})
    public ItooResult queryPageAll(@ApiParam(name = "pageNo", value = "页码", required = true, example = "1") @PathVariable Integer pageNo,
                                   @ApiParam(name = "pageSize", value = "页数", required = true, example = "10") @PathVariable Integer pageSize) {
        return staffInstitutionApi.queryPageAll(pageNo, pageSize);
    }

    /**
     * 根据职工id模糊查询staffInstitution
     *
     * @param staffId  职工id
     * @param pageNo   页码
     * @param pageSize 页数
     * @return 模糊查询的staffInstitution
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据职工id模糊查询staffInstitution", notes = "分页根据职工id模糊查询staffInstitution")
    @GetMapping(value = "queryStaffInstitutionByLikeStaffId/{pageNo}/{pageSize}")
    public ItooResult queryStaffInstitutionByLikeStaffId(@RequestParam(required = false, defaultValue = "") String staffId,
                                                         @ApiParam(value = "页码", required = true, example = "1") @PathVariable Integer pageNo,
                                                         @ApiParam(value = "记录数", required = true, example = "10") @PathVariable Integer pageSize) {
        return staffInstitutionApi.queryStaffInstitutionByLikeStaffId(staffId, pageNo, pageSize);
    }
    //endregion

    /* **********************************以下为非模板生成的内容********************************* */

    /**
     * 根据教师id查找该学院所有教师的ID和名称
     *
     * @param staffId 教师ID
     * @author 杨江涛
     * @since 2.0.0 2018年11月27日15:59:36
     */
    @ApiOperation(value = "根据教师id查找该学院所有教师的ID和名称（本方法不完整，该数据库表暂未使用，可以删除该数据库表2018-11-27 20:48:51）")
    @GetMapping(value = {"/findByStaffId/{staffId}"})
    public ItooResult findByStaffId(@ApiParam(value = "教师id", required = true) @PathVariable String staffId) {
        List<StaffInstitutionEntity> staffInstitutionEntityList = staffInstitutionService.findByStaffId(staffId);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", staffInstitutionEntityList);
    }

}    
